﻿<div class="layui-card" id="lg-AdminList">
    <div class="layui-card-header"><i class="fa fa-home fa-fw"></i>管理员</div>
    <div class="layui-card-body" id="">
        <div class="lg-form-box">
            <table class="layui-hide" id="AdminList" lay-filter="AdminList"></table>
        </div>
        <!-- 内容主体区域结束 -->
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add"><i class="fa fa-plus fa-fw"></i>添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="refresh"><i class="fa fa-refresh fa-fw"></i>刷新</button>
    </div>
</script>
<script type="text/html" id="btTpl">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit" title="编辑"><span class="fa fa-pencil-square-o fa-fw "></span></a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="del" title="删除"><span class="fa fa-trash-o fa-fw"></span></a>
</script>
<script type="module">
    console.log(window);
    console.log(freeForm);
    frame.createPage({
        mounted: function() {
            var page = this;
            var page = this;
            page.vm = Vue.createApp({
                data() {
                    return {

                    }
                },
                mounted: function() {
                    this.TableRender();
                },
                methods: {
                    TableRender: function() {
                        layui.use(['table', 'element', 'form'], function() {
                            var table = layui.table;
                            var form = layui.form;
                            form.render();
                            page.laytable = table.render({
                                elem: '#AdminList'
                                , url: '/base/getAdmins'
                                , toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
                                , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                                , cols: [[
                                    { type: 'checkbox' }
                                    , {
                                        field: 'Id', title: '序号', width: 80, templet: function(d) {
                                            return d.LAY_TABLE_INDEX + 1;
                                        }
                                    }
                                    , { field: 'Account', title: '账户名' }
                                    , { field: 'TrueName', title: '姓名' }
                                    , { field: 'RoleName', title: '角色' }
                                    , { field: 'Phone', title: '电话' }
                                    , { field: 'Email', title: '邮箱' }
                                    , {
                                        field: 'IsLock', title: '锁定', width: 90, templet: function(d) {
                                            return laySwitch.render(d.isLock, 'lock');
                                        }
                                    }
                                    , { fixed: 'right', title: '操作', width: 160, toolbar: '#btTpl' }
                                ]]
                                , page: true
                            });
                            table.on('toolbar(AdminList)', function(obj) {
                                var checkStatus = table.checkStatus(obj.config.id);
                                switch (obj.event) {
                                    case 'add':
                                        frame.NavigateTo({
                                            url: "/lgm/admin/add",
                                            title: "添加年级"
                                        })
                                        break;
                                    case 'refresh':
                                        page.laytable.reload();
                                        break;
                                };
                            })
                            table.on('tool(AdminList)', function(obj) {
                                var data = obj.data;
                                switch (obj.event) {
                                    case 'use':
                                        laySwitch.do({
                                            obj: obj,
                                            key: "IsUsing",
                                            url: "/base/EditAdmin",
                                            refresh: function() {
                                                page.laytable.reload();
                                            }
                                        })
                                        break;
                                    case 'lock':
                                        laySwitch.do({
                                            obj: obj,
                                            key: "IsLock",
                                            url: "/base/EditAdmin",
                                            refresh: function() {
                                                page.laytable.reload();
                                            }
                                        })
                                        break;
                                    case 'edit':
                                        frame.NavigateTo({
                                            url: "/lgm/admin/Edit/" + data.Id,
                                            title: "编辑管理员"
                                        })
                                        break;
                                    case 'del':
                                        layer.confirm('真的删除行么', function(index) {
                                            lg.request({
                                                url: "/base/deleteAdmin",
                                                method: "post",
                                                data: { id: data.Id },
                                                success: res => {
                                                    if (res.code == 0) {
                                                        obj.del();
                                                    }
                                                }
                                            })
                                            layer.close(index);
                                        });
                                        break;
                                };
                            })
                        });
                    },

                }
            }).mount("#lg-AdminList")
        },
    }).mount();

</script>